﻿//-----------------------------------------------------------------------
// <copyright file="ContactManager.cs" company="FastNET Services">
//     Copyright (c) 2007-2011. All Rights Reserved.
// </copyright>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using FastNet.BusinessSystem.Managers;
using FastNet.RepositorySystem;
using SampleBusiness.Objects;
using SampleRepository.Entities;
using SampleRepository.Repositories;
#endregion

namespace SampleBusiness.Managers
{
    public class ContactManager : IdentityBusinessManager<Contact, IContactRepository, IContactData>
    {
        #region CTor/DTor

        /// <summary>
        /// Initializes a new instance of ContactManager
        /// </summary>
        internal ContactManager()
            : base(new RepositoryFactory())
        {
        }

        #endregion

        #region Conversions

        /// <summary>
        /// Converts IContactData to Contact based on the inheriting class rules
        /// </summary>
        /// <param name="data">IContactData to convert</param>
        /// <returns>Contact Generated</returns>
        protected override Contact ConvertData(IContactData data)
        {
            return new Contact(Factory, data);
        }

        #endregion

        /// <summary>
        /// Retrieve a contact given a shipping address ID
        /// </summary>
        /// <param name="shippingId">Identity of the shipping address associated with the contact</param>
        /// <returns>IContactData that was found or NULL if no contact was found</returns>
        /// <exception cref="InvalidOperationException">Thrown if the Identity provided does not match the type of the underlying provider</exception>
        public Contact RetreiveByShippingAddressId(Identity shippingId)
        {
            return ConvertData(Repository.RetrieveByShippingAddressId(shippingId));
        }
    }
}
